package org.grow.share.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PersonController {
    @ResponseBody
    @PostMapping("/personForm")
    public Person personForm(@RequestParam String name,
                             @RequestParam int age,
                             @RequestParam boolean male){

        System.out.println(name+age+male);
        return new Person(name,age,male);
    }
    @ResponseBody
    @PostMapping("/personAjax")
    public Person personForm(@RequestBody Person person){
        System.out.println(person);
        return person;
    }
}
class Person{
    private String name;
    private int age;
    private boolean male;

    public Person(String name, int age, boolean male) {
        this.name = name;
        this.age = age;
        this.male = male;
    }

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public boolean isMale() {
        return male;
    }

    public void setMale(boolean male) {
        this.male = male;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", male=" + male +
                '}';
    }
}